home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d20 / dorskel2.arc / ANSI.ASM next >
Assembly Source File  |  1991-12-05  |  13KB  |  404 lines

  1. ; this is ripped off from pd code in RBBS-ASM (was ANSI1-7.ASM)
  2. ; has been heavily modified by M. Kimes, who isn't much of an
  3. ; asm-programmer.  Now works with C in a strange way and supports
  4. ; configurable window.  It's momma wouldn't know it now (and probably
  5. ; would claim it's the type of program she warned it about).
  6. ; I reckon it was public domain before, and still is.
  7. ;
  8. ; int  far pascal ansi      (char far *str);
  9. ; void far pascal setcoords (int topx,int topy,int botx,int boty);
  10. ; void far pascal getcoords (int far *topx,int far *topy,int far *botx,int far *boty);
  11. ;
  12.  
  13. .model large
  14.  
  15. ANSI_PRNT SEGMENT PUBLIC 'CODE'
  16.           ASSUME CS:ANSI_PRNT
  17.           PUBLIC ANSI,SETCOORDS,GETCOORDS
  18.           PUBLIC _atop,_atopy,_atopx,_abot,_aboty,_abotx
  19.  
  20. formfeed          equ 12
  21.  
  22. VID_PAGE          DB 0                  ;Active video page
  23. _atop             LABEL WORD
  24. _atopy            DB 0                  ;top y coord
  25. _atopx            DB 0                  ;top x coord
  26. _abot             LABEL WORD
  27. _aboty            DB 17h                ;bottom y coord
  28. _abotx            DB 4Fh                ;bottom x coord
  29. _fastansiout      DB 1                  ;fast ansi writes?
  30.  
  31.  
  32. GETCOORDS PROC    FAR   ;void pascal far getcoords(int *topx,int *topy,
  33.                         ;                          int *botx,int *boty);
  34.  
  35. ; get window coordinates (0 based)
  36.  
  37.           PUSH    BP
  38.           MOV      BP,SP
  39.           PUSH    DS
  40.           MOV     AH,0
  41.           MOV     AL,_atopx
  42.           MOV     BX,[BP]+18
  43.           MOV     DS,[BP]+20
  44.           MOV     [BX],AX
  45.           MOV     AL,_atopy
  46.           MOV     DS,[BP]+16
  47.           MOV     BX,[BP]+14
  48.           MOV     [BX],AX
  49.           MOV     AL,_abotx
  50.           MOV     DS,[BP]+12
  51.           MOV     BX,[BP]+10
  52.           MOV     [BX],AX
  53.           MOV     AL,_aboty
  54.           MOV     DS,[BP]+8
  55.           MOV     BX,[BP]+6
  56.           MOV     [BX],AX
  57.           POP     DS
  58.           POP      BP
  59.           RET     16
  60.  
  61. GETCOORDS ENDP
  62.  
  63. SETCOORDS PROC    FAR   ;void pascal far setcoords(int topx,int topy,
  64.                         ;                          int botx,int boty);
  65.  
  66. ; set window coordinates (0 based)
  67.  
  68.           PUSH    BP
  69.           MOV      BP,SP
  70.           MOV     AH,[BP]+12
  71.           MOV     _atopx,AH
  72.           MOV     AH,[BP]+10
  73.           MOV     _atopy,AH
  74.           MOV     AH,[BP]+8
  75.           MOV     _abotx,AH
  76.           MOV     AH,[BP]+6
  77.           MOV     _aboty,AH
  78.           POP      BP
  79.           RET     8
  80.  
  81. SETCOORDS ENDP
  82.  
  83.  
  84.  
  85. SETFASTANSI PROC    FAR   ;void pascal far setfastansi(int fast);
  86.  
  87. ; set fast ansi (0 = off)
  88.  
  89.           PUSH    BP
  90.           MOV      BP,SP
  91.           MOV     AH,[BP]+6
  92.           MOV     _fastansiout,AH
  93.           POP      BP
  94.           RET     2
  95.  
  96. SETFASTANSI ENDP
  97.  
  98.  
  99.  
  100. ANSI      PROC    FAR   ;int pascal far ansi(char far *str);
  101.  
  102. ; display a string through DOS' ANSI driver, respecting a window
  103.  
  104.           PUSH    BP                    ;set up stack frame
  105.           MOV     BP,SP
  106.  
  107.           PUSH    DS                    ;save ds
  108.  
  109.           MOV     AH,15                 ;get current video state
  110.           INT     10H
  111.           MOV     VID_PAGE,BH           ;save it
  112.  
  113.           MOV     BX,[BP]+6             ;get string address
  114.           MOV     DS,[BP]+8             ;set ds
  115.           PUSH    BX                    ;save original address
  116.  
  117. ALOOP:
  118.           MOV     DL,[BX]               ;set dl to char to print
  119.           CMP     DL,27                 ;escape?
  120.           JNZ     GOON                  ;no, skip all this...
  121.           CMP     BYTE PTR [BX]+1,'['   ; check for various ansi
  122.           JNZ     GOON                  ; commands that would screw
  123.           CMP     BYTE PTR [BX]+2,'2'   ; up our window
  124.           JNZ     GOON1                 ; \x1b[2J
  125.           CMP     BYTE PTR [BX]+3,'J'
  126.           JNZ     GOON2
  127.           ADD     BX,4
  128.           CALL    CLEARSCRN
  129.           JMP     ALOOP
  130. GOON1:
  131.           CMP     BYTE PTR [BX]+2,'K'   ; \x1b[K
  132.           JNZ     GOON3
  133.           ADD     BX,3
  134.           CALL    CLEARLINE
  135.           JMP     ALOOP
  136. GOON3:
  137.           CMP     BYTE PTR [BX]+2,'k'   ;\x1b[k
  138.           JNZ     GOON
  139.           ADD     BX,3
  140.           CALL    CLEAREOL
  141.           JMP     ALOOP
  142. GOON2:
  143.           CMP     BYTE PTR [BX]+3,'j'   ;\x1b[2j
  144.           JNZ     GOON
  145.           ADD     BX,4
  146.           CALL    CLEAREOS
  147.           JMP     ALOOP
  148. GOON:
  149.           CMP     DL,0                ;End of string?
  150.           JNZ     NOEXIT1
  151.           JMP     EXIT1
  152. NOEXIT1:                            
  153.           CALL    DOCHECKPOS        ;check cursor pos; protect window
  154.           CMP     _fastansiout,0    ;fast ansi writes?
  155.           JZ      SLOWWRITES        ;nope
  156.           MOV     AX,DX             ;yep
  157.           INT     29H
  158.           JMP     SKIPSLOW
  159. SLOWWRITES:
  160.           MOV     AH,2
  161.           INT     21H               ;display it
  162. SKIPSLOW:
  163.           INC     BX
  164.           CMP     BYTE PTR [BX],0   ;end of string?
  165.           JZ      EXIT1             ;yep
  166.           JMP     ALOOP             ;nope
  167. EXIT1:                              ;wrap it up...
  168.           CALL    DOCHECKPOS
  169.           POP     AX                ;retrieve old start pos
  170.           SUB     BX,AX             ;subtract from current pos
  171.           MOV     AX,BX             ;return length of string printed
  172.  
  173.           POP     DS
  174.           POP     BP
  175.           RET     4
  176.  
  177. ANSI      ENDP
  178.  
  179.  
  180.  
  181. DOCHECKPOS:                         ;check cursor pos, protect window
  182.           PUSH    AX                ;Save the registers that will be affected
  183.           PUSH    BX
  184.           PUSH    CX
  185.           PUSH    DX
  186.           CALL    WHERE_ARE_WE      ; where the cursor is.......
  187.           CMP     DH,_atopy
  188.           JGE     CHECKTOPX
  189.           MOV     AH,2
  190.           MOV     DH,_atopy
  191.           PUSH    BX
  192.           MOV     BH,VID_PAGE
  193.           INT     10H
  194.           POP     BX
  195. CHECKTOPX:
  196.           CMP     DL,_atopx
  197.           JGE     CHECKBOTX
  198.           MOV     AH,2
  199.           MOV     DL,_atopx
  200.           PUSH    BX
  201.           MOV     BH,VID_PAGE
  202.           INT     10H
  203.           POP     BX
  204.           JMP     CHECKROW
  205. CHECKBOTX:
  206.           CMP     DL,_abotx
  207.           JLE     CHECKROW
  208.           MOV     DL,_atopx
  209.           INC     DH
  210.           MOV     AH,2
  211.           PUSH    BX
  212.           MOV     BH,VID_PAGE
  213.           INT     10H
  214.           POP     BX
  215. CHECKROW:
  216.           CMP     DH,_aboty         ; Row ???
  217.           JLE     OUTTAHERE         ; Jump if less
  218.           CALL    SCROLLIT          ; else scroll, we're too low
  219.           MOV     DH,_aboty         ; put cursor back in window
  220.           PUSH    BX
  221.           MOV     BH,VID_PAGE
  222.           INT     10H
  223.           POP     BX
  224. OUTTAHERE:
  225.           POP     DX                ;Restore the stack like it was
  226.           POP     CX
  227.           POP     BX
  228.           POP     AX
  229.           RET
  230.  
  231.  
  232. WHERE_ARE_WE:                       ;Get the current cursor position
  233.           PUSH    AX                ;Save the registers
  234.           PUSH    BX
  235.           PUSH    CX
  236.           MOV     AH,03             ;SET UP FOR ROM-BIOS CALL (03H)
  237.           MOV     BH,VID_PAGE       ;TO READ THE CURRENT CURSOR POSITION
  238.           INT     10H               ; DH = ROW   DL = COLUMN
  239.           POP     CX                ;Restore the registers
  240.           POP     BX
  241.           POP     AX
  242.           RET                        ;And go back from wence we came
  243.  
  244.  
  245. SCROLLIT: PUSH    AX                ;Save the registers that will be affected
  246.           PUSH    BX
  247.           PUSH    CX
  248.           PUSH    DX
  249.           PUSH    BP
  250.           MOV     AH,2              ;Now set cursor position to ???,???
  251.           MOV     DH,_aboty
  252.           MOV     DL,_atopx
  253.           MOV     BH,VID_PAGE       ;attribute
  254.           INT     10H
  255.           MOV     AH,8              ;Get the current character attribute
  256.           MOV     BH,VID_PAGE
  257.           INT     10H
  258.           MOV     BH,AH             ;Transfer the attribute to BH for next call
  259.           MOV     AH,6              ;Otherwise scroll ??? lines
  260.           MOV     AL,1              ;Only blank line ???
  261.           MOV     CH,_atopy
  262.           MOV     CL,_atopx
  263.           MOV     DH,_aboty
  264.           MOV     DL,_abotx
  265.           INT     10H               ;And do it.......
  266.           MOV     AH,2              ;Now set cursor position to ???,???
  267.           MOV     DH,_aboty
  268.           MOV     DL,_atopx
  269.           MOV     BH,VID_PAGE
  270.           INT     10H
  271.           POP     BP
  272.           POP     DX                ;Restore the stack like it was
  273.           POP     CX
  274.           POP     BX
  275.           POP     AX
  276.           RET
  277.  
  278. CLEARSCRN:                          ;Clear current window
  279.           PUSH    AX                ;Save the registers
  280.           PUSH    BX
  281.           PUSH    CX
  282.           PUSH    DX
  283.           PUSH    BP
  284.           MOV     AH,2              ;Now set cursor position to ???,???
  285.           MOV     DH,_aboty
  286.           MOV     DL,_atopx
  287.           MOV     BH,VID_PAGE       ;attribute
  288.           INT     10H
  289.           MOV     AH,8              ;Get the current character attribute
  290.           MOV     BH,VID_PAGE
  291.           INT     10H
  292.           MOV     BH,AH             ;Transfer the attribute to BH for next call
  293.           MOV     AH,6              ;Otherwise scroll ??? lines
  294.           MOV     AL,0              ;clear screen
  295.           MOV     CH,_atopy
  296.           MOV     CL,_atopx
  297.           MOV     DH,_aboty
  298.           MOV     DL,_abotx
  299.           INT     10H               ;And do it.......
  300.           MOV     AH,2              ;Now set cursor position to ???,???
  301.           MOV     DH,_atopy
  302.           MOV     DL,_atopx
  303.           MOV     BH,VID_PAGE
  304.           INT     10H
  305.           POP     BP
  306.           POP     DX                ;Restore the stack like it was
  307.           POP     CX
  308.           POP     BX
  309.           POP     AX
  310.           RET
  311.  
  312. CLEAREOS:                           ;Clear to end of current window
  313.           PUSH    AX                ;Save the registers
  314.           PUSH    BX
  315.           PUSH    CX
  316.           PUSH    DX
  317.           PUSH    BP
  318.           MOV     AH,8              ;Get the current character attribute
  319.           MOV     BH,VID_PAGE
  320.           INT     10H
  321.           MOV     BH,AH             ;Transfer the attribute to BH for next call
  322.           MOV     AH,6              ;Otherwise scroll ??? lines
  323.           MOV     AL,0              ;clear
  324.           CALL    WHERE_ARE_WE
  325.           PUSH    DX                ;save it
  326.           MOV     CX,DX
  327.           MOV     DH,_aboty
  328.           MOV     DL,_abotx
  329.           INT     10H               ;And do it.......
  330.           MOV     AH,2
  331.           MOV     BH,VID_PAGE
  332.           POP     DX
  333.           INT     10H               ;restore position
  334.           POP     BP
  335.           POP     DX                ;Restore the stack like it was
  336.           POP     CX
  337.           POP     BX
  338.           POP     AX
  339.           RET
  340.  
  341. CLEARLINE:                          ;Clear current line
  342.           PUSH    AX                ;Save the registers
  343.           PUSH    BX
  344.           PUSH    CX
  345.           PUSH    DX
  346.           PUSH    BP
  347.           MOV     AH,8              ;Get the current character attribute
  348.           MOV     BH,VID_PAGE
  349.           INT     10H
  350.           CALL    WHERE_ARE_WE
  351.           PUSH    DX                ;save it
  352.           MOV     BH,AH             ;Transfer the attribute to BH for next call
  353.           MOV     AH,6              ;Otherwise scroll ??? lines
  354.           MOV     AL,0              ; clear line
  355.           MOV     CX,DX
  356.           MOV     CL,_atopx
  357.           MOV     DL,_abotx
  358.           INT     10H               ; And do it.......
  359.           MOV     AH,2              ;Now set cursor position to ???,???
  360.           MOV     DL,_atopx
  361.           MOV     BH,VID_PAGE
  362.           INT     10H
  363.           MOV     AH,2
  364.           MOV     BH,VID_PAGE
  365.           POP     DX
  366.           INT     10H               ;restore position
  367.           POP     BP
  368.           POP     DX                ;Restore the stack like it was
  369.           POP     CX
  370.           POP     BX
  371.           POP     AX
  372.           RET
  373.  
  374. CLEAREOL:                           ;Clear to end of current line
  375.           PUSH    AX                ;Save the registers
  376.           PUSH    BX
  377.           PUSH    CX
  378.           PUSH    DX
  379.           PUSH    BP
  380.           MOV     AH,8              ;Get the current character attribute
  381.           MOV     BH,VID_PAGE
  382.           INT     10H
  383.           CALL    WHERE_ARE_WE
  384.           PUSH    DX                ;save it
  385.           MOV     BH,AH             ;Transfer the attribute to BH for next call
  386.           MOV     AH,6              ;Otherwise scroll ??? lines
  387.           MOV     AL,0              ;clear line
  388.           MOV     CX,DX
  389.           MOV     DL,_abotx
  390.           INT     10H               ;And do it.......
  391.           MOV     AH,2
  392.           MOV     BH,VID_PAGE
  393.           POP     DX
  394.           INT     10H               ;restore position
  395.           POP     BP
  396.           POP     DX                ;Restore the stack like it was
  397.           POP     CX
  398.           POP     BX
  399.           POP     AX
  400.           RET
  401.  
  402. ANSI_PRNT ENDS
  403.           END
  404.